﻿using System.ComponentModel;
using System.Text;

namespace PhotoKiosk.Model
{
    public class PaperSize : INotifyPropertyChanged
    {
        public int Width
        {
            get;
            set;
        }

        public int Height
        {  set; get; }

        public float Price
        {  set; get; }

        public string Name
        {
            get
            {
                StringBuilder s = new StringBuilder();
                s.AppendFormat("{0} x {1}", Width.ToString(), Height.ToString());
                return s.ToString();
            }
            private set
            {

            }
        }

        public PaperSize(int i_Width, int i_Height, float i_Price)
        {
            Width = i_Width;
            Height = i_Height;
            Price = i_Price;
        }

        public override string ToString()
        {
            StringBuilder s = new StringBuilder();
            s.AppendFormat("{0} x {1}", Width.ToString(), Height.ToString());
            return s.ToString();
        }

        public static string ParseToXML(PaperSize i_input)
        {
            return i_input.Width + "," + i_input.Height + "," + i_input.Price;
        }

        public static PaperSize Parse(string i_input)
        {
            return new PaperSize(int.Parse(i_input.Split(new char[] { ',' })[0].ToString()), int.Parse(i_input.Split(new char[] { ',' })[1].ToString()), float.Parse(i_input.Split(new char[] { ',' })[2].ToString()));
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
                var e = new PropertyChangedEventArgs(propertyName);
                handler(this, e);
            }
        }
    }
}
